package com.hedl.practice.diyJava.multithreading.wait_notify.tmp;

import java.util.LinkedList;
import java.util.Queue;

public class TaskQueue {
    Queue<String> queue = new LinkedList<>();

    public synchronized void addTask(String s){
        this.queue.add(s);
        this.notifyAll();       //唤醒全部线程
    }

    public synchronized String getTask() throws InterruptedException {
        while(queue.isEmpty()){
            this.wait();        //唤醒，获得锁
        }
        return queue.remove();  //取出元素，在删除；
    }       //释放锁
}
